(defun lisp-defun(&optional functionName)
  (interactive)
  (or functionName (setq functionName (read-from-minibuffer "Enter function Name: ")))
  (insert (format "(defun %s()
  \"\"
  (interactive)
  (insert \"\")
  )" functionName))
)

(defun lisp-minibuffer(&optional name)
  (interactive)
  (or name (setq name (read-from-minibuffer "Enter Parameter Name: ")))
  (insert (format ";; &optional %s
(or %s (setq %s (read-from-minibuffer \"Enter %s Name: \")))" name name name name))
  )

(defun lisp-regex()
  (interactive)
  (insert "(defun multiline-regex()
  (interactive)
  (while (re-search-forward \"if (.*)
  {
.*
    Devicehardware = new \\(.*\\)(address);
  }\")
    (replace-match \"return typeof(\\1);\")
    )
  )")
  )

(defun multiline-regex(search replace)
  (interactive)
  (while (re-search-forward search)
    (replace-match replace)
    )
  )

(defun lisp-minormode()
  (interactive)
  (insert "(define-minor-mode foo-mode \"If enabled, foo on you!\"
    :lighter \" Foo\" :require 'foo :global t :group 'hassle :version \"27.5\"
    )
    ")
  )

(defun lisp-re-search-forward()
  (interactive)
  (insert "(defun replace-quote()
  (interactive)
  (beginning-of-buffer)
  ;; (setq words (match-string 1))
  (while (re-search-forward \"+=\" nil t)
    (replace-match \"-=\")
    )
  (beginning-of-buffer)
  (while (re-search-forward \"new .*(\\\\(.*\\\\));\" nil t)
    (replace-match \"\\\\1;\")
    )
  )")
  )

(defun lisp-word()
  (interactive)
  (insert "(let ((word (if mark-active
                  (buffer-substring-no-properties (region-beginning) (region-end))
                (current-word nil t))))

)
")
  )

(defun lisp-filter()
  (interactive)
  (insert "(defun lisp-filter()
  (interactive)
  (beginning-of-buffer)
  (setq word-to-be-expand \"+=\")
  (with-output-to-temp-buffer \"*Result*\"  
    (while (re-search-forward word-to-be-expand nil t)
      (move-beginning-of-line 1)
      (setq line-begin (point))
      (move-end-of-line 1)
      (setq line-end (point))
      (setq temp (buffer-substring-no-properties line-begin line-end))
      (princ (format \"%s\\n\" temp))
      ))
  
  (switch-to-buffer-other-window \"*Result*\")
  (toggle-read-only nil)
  (csharp-mode)
  (replace-quote)
)")
  )

(defun lisp-global-set-key()
  (interactive)
  (insert "(global-set-key [(meta g)] 'goto-line)
(global-set-key (kbd \"C-x C-g\") 'lgrep)
(global-set-key [C-f1] 'ispell)
(global-set-key [f2] 'shell)
(global-set-key \"\\C-c\\C-d\" \"\\C-a\\C- \\C-e\\M-w\\C-a\")
")
  )

(defun lisp-menu()
  (interactive)
  (insert "(x-popup-menu
 t
 '(\"Title\"
   (\"Title 1\" (\"Item 1-1\" . 11) (\"Item 1-2\" . 12))
   (\"Title 2\" (\"Item 2-1\" . 21) (\"Item 2-2\" . 22))))")
  )

(global-set-key (kbd "C-c e d") 'lisp-defun)

(defun lisp-while()
  (interactive)
  (insert "(setq abc '(1 2 3 4 5))
 (setq i 0)
 (setq length-abc (length abc))

 (while (< i length-abc)
  (print (nth i abc))
  (setq i (+ 1 i)
  )")
  )

(defun lisp-while-threelayer()
  "three layer "
  (interactive)
  (insert "

(setq dayType '(
\"Monday\"
\"Tuesday\"
\"Wednesday\"
\"Thursday\"
\"Friday\"
\"Saturday\"
\"Sunday\"
\"HolidayOne\"
\"HolidayTwo\"
\"HolidayThree\")
)

(setq interval '(
\"IntervalOne\"
\"IntervalTwo\"
\"IntervalThree\")
)

(setq startStop '(
\"Start\"
\"Stop\"
)
)

(setq length-dayType (length dayType))
(setq length-interval (length interval))
(setq length-startStop (length startStop))

(setq i 0)
(while (< i length-dayType)

  (setq j 0)  
  (while (< j length-interval)
    (setq k 0)    
    (while (< k length-startStop)

      (insert (format \"rmeb%s%s%s\\n\" (nth i dayType) (nth j interval) (nth k startStop)))
      
      (setq k (+ 1 k))
      )
    
    (setq j (+ 1 j))
    )

  (setq i (+ 1 i))
  )
")
  )

(defun lisp-string-endwith()
  (interactive)
  (insert "(defun end-with-string-p (s ending)
      \"return non-nil if string S ends with ENDING.\"
      (cond ((>= (length s) (length ending))
             (let ((elength (length ending)))
               (string= (substring s (- 0 elength)) ending)))
            (t nil)))")
  )

(defun lisp-recursion()
  (interactive)
  (insert "  (defun directory-dirs (dir)
    \"Find all directories in DIR.\"
    (unless (file-directory-p dir)
      (error \"Not a directory `%s'\" dir))
    (let ((dir (directory-file-name dir))
          (dirs '())
          (files (directory-files dir nil nil t)))
        (dolist (file files)
          (unless (member file '(\".\" \"..\"))
            (let ((file (concat dir \"/\" file)))
              (when (file-directory-p file)
                (setq dirs (append (cons file
                                         (directory-dirs file))
                                   dirs))))))
        dirs))")
  )


(defun lisp-command()
  "run command in shell"
  (interactive)
  (insert "(start-process-shell-command \"cmd.exe\" \"c run history\" \"open -n /SystemSoftware/eclipse/Eclipse.app\")")
  )

(defun lisp-split-word()
  ""
  (interactive)
  (insert "(defun split-word()
  (interactive)
  (beginning-of-buffer)
  (with-output-to-temp-buffer \"100\"
    (while (re-search-forward \"\\\\([A-Za-z]+\\\\)\" nil t)
      (princ (match-string 1))
      (princ \"\\n\")
      )
    )
  )")
  )

(defun lisp-duplicate()
  ""
  (interactive)
  (insert "(defun remove-duplicate()
  \"\"
  (interactive)
  (while (re-search-forward \"\\\\([A-Za-z]+
\\\\)\\\\1+\" nil t)
    (replace-match \"\\\\1\")
    )
  )")
  )


(defun lisp-list()
  ""
  (interactive)
  (insert "(defun quick-replace()
  \"\"
  (interactive)
  (setq list '((\"Accessed\" \"Access\")
               (\"AllPointsDeisolated\" \"AllPointsDeisolate\")
               )
        )  
    (while list
      (setq temp (car list))
      (setq list (cdr list))
      (setq first (car temp))
      (setq last (car (cdr temp)))
      (beginning-of-buffer)
      (while (re-search-forward (format \"TransactionProvider_%s,\" first) nil t)
        (replace-match (format \"TransactionProvider_%s,\" last))
        )
      ;; (princ first)
      ;; (princ \"\\n\")
      ;; (princ last)
      ;; (princ \"\\n\")
    )
  )")
  )


(defun lisp-font-lock()
  ""
  (interactive)
  (insert "(setq myKeywords
 '((\"Sin\\\\|Cos\\\\|Sum\" . font-lock-function-name-face)
   (\"Pi\\\\|Infinity\" . font-lock-constant-face)
  )
)

(define-derived-mode math-lang-mode fundamental-mode
  (setq font-lock-defaults '(myKeywords))
  (setq mode-name \"math lang\")
)")
  )